<?php


class CVIncludes {

	/**
	 * PHP4 constructor method.  This simply provides backwards compatibility for users with setups
	 * on older versions of PHP.  Once WordPress no longer supports PHP4, this method will be removed.
	 *
	 * @since 1.2.0
	 */
	function CVIncludes() {
		$this->__construct();
	}

	/**
	 * Constructor method for the CVIncludes class.  This method adds other methods of the class to 
	 * specific hooks within WordPress.  It controls the load order of the required files for running 
	 * the framework.
	 *
	 * @since 1.2.0
	 */
	function __construct() {

		/* Define CVIncludes parent theme, and child theme constants. */
		add_action( 'after_setup_theme', array( &$this, 'constants' ), 1 );

		/* Load the CVIncludes functions. */
		add_action( 'after_setup_theme', array( &$this, 'modules' ), 12 );		
	}

	/**
	 * Defines the constant paths for use within the core CVIncludes, parent theme, and
	 * child theme.  Constants prefixed with 'CVINCLUDES_' are for use only within the core
	 * framework and don't reference other areas of the parent or child theme.
	 *
	 * @since 1.2.0
	 */
	function constants() {

		$themedata = get_theme_data(STYLESHEETPATH . '/style.css');
		define('THEME_NAME', $themedata['Name']);
		
		define('CV_THEME_VERSION', $themedata['Version']);
		
    	/* Sets the path to the parent theme directory. */
		define( 'CV_THEME_DIR', get_template_directory() );
		
		/* Sets the path to the parent theme directory URI. */
		define( 'CV_THEME_URI', get_template_directory_uri() );
		
		define('THEME_FUNCTIONS_DIR', trailingslashit(CV_THEME_DIR) . 'functions');	
		define('THEME_FUNCTIONS_URI', trailingslashit(CV_THEME_URI) . 'functions');	
		
		define( 'THEME_STYLES_DIR', trailingslashit( CV_THEME_DIR ) . 'styles' );		
		define( 'THEME_STYLES_URI', trailingslashit( CV_THEME_URI ) . 'styles' );
		
		define( 'CVINCLUDES_DIR', trailingslashit( CV_THEME_DIR ) . basename( dirname( __FILE__ ) ) );		
		define( 'CVINCLUDES_URI', trailingslashit( CV_THEME_URI ) . basename( dirname( __FILE__ ) ) );			
		
		define('CVINCLUDES_SLIDES_URI', trailingslashit( CVINCLUDES_URI ) . 'slides');		
		define('CVINCLUDES_SLIDES_DIR', trailingslashit( CVINCLUDES_DIR ) . 'slides');
		
		define('CVINCLUDES_OPTIONS_DIR', trailingslashit( CVINCLUDES_DIR ) . 'options');		
		define('CVINCLUDES_OPTIONS_URI', trailingslashit( CVINCLUDES_URI ) . 'options');
		
		define('CVINCLUDES_SHORTCODE_DIR', trailingslashit( CVINCLUDES_DIR ) . 'shortcode');		
		define('CVINCLUDES_SHORTCODE_URI', trailingslashit( CVINCLUDES_URI ) . 'shortcode');
		
		define('CVINCLUDES_SEO_DIR', trailingslashit( CVINCLUDES_DIR ) . 'seo');
		define('CVINCLUDES_SEO_URI', trailingslashit( CVINCLUDES_URI ) . 'seo');

		define('CVINCLUDES_SOCIALMEDIA_DIR', trailingslashit( CVINCLUDES_DIR ) . 'socialmedia');
		define('CVINCLUDES_SOCIALMEDIA_URI', trailingslashit( CVINCLUDES_URI ) . 'socialmedia');
		
		define('CVINCLUDES_DROPDOWNS_DIR', trailingslashit( CVINCLUDES_DIR ) . 'dropdowns');
		define('CVINCLUDES_DROPDOWNS_URI', trailingslashit( CVINCLUDES_URI ) . 'dropdowns');

		//define('CVINCLUDES_GOOGLEFONTS_DIR', trailingslashit( CVINCLUDES_DIR ) . 'google-fonts');
		//define('CVINCLUDES_GOOGLEFONTS_URI', trailingslashit( CVINCLUDES_URI ) . 'google-fonts');			
		
		//define('CVINCLUDES_LAYOUTS_DIR', trailingslashit( CVINCLUDES_DIR ) . 'layouts');
		
		define('CVINCLUDES_FUNCTIONS_DIR', trailingslashit( CVINCLUDES_DIR ) . 'functions');
		
		define('CVINCLUDES_PORTFOLIO_URI', trailingslashit( CVINCLUDES_URI ) . 'portfolio');
		define('CVINCLUDES_PORTFOLIO_DIR', trailingslashit( CVINCLUDES_DIR ) . 'portfolio');

		define('CVINCLUDES_EZTABLES_URI', trailingslashit( CVINCLUDES_URI ) . 'eztables');
		define('CVINCLUDES_EZTABLES_DIR', trailingslashit( CVINCLUDES_DIR ) . 'eztables');				
		
	}

	
	
	/**
	 * Loads the CVIncludes modules.  Many of these functions are needed to properly run the 
	 * framework.  Some components are only loaded if the theme supports them.
	 *
	 * @since 1.2.0
	 */
	function modules() {
	
		require_once(trailingslashit( CVINCLUDES_FUNCTIONS_DIR ) . 'functions.php' );
		/* Load the modules module if supported. */	
		require_if_theme_supports( 'cvincludes-options', trailingslashit( CVINCLUDES_OPTIONS_DIR ) . 'options.php' );	

		//require_if_theme_supports( 'cvincludes-google-fonts', trailingslashit( CVINCLUDES_GOOGLEFONTS_DIR ) . 'google-fonts.php' );
		
		require_if_theme_supports( 'cvincludes-slides', trailingslashit( CVINCLUDES_SLIDES_DIR ) . 'slides.php' );
		
		require_if_theme_supports( 'cvincludes-shortcode', trailingslashit( CVINCLUDES_SHORTCODE_DIR ) . 'shortcode.php' );
		
		require_if_theme_supports( 'cvincludes-seo', trailingslashit( CVINCLUDES_SEO_DIR ) . 'seo.php' );		
		
		require_if_theme_supports( 'cvincludes-socialmedia', trailingslashit( CVINCLUDES_SOCIALMEDIA_DIR ) . 'socialmedia.php' );
		
		//require_if_theme_supports( 'theme-layouts', trailingslashit( CVINCLUDES_LAYOUTS_DIR ) . 'layouts.php' );
		
		require_if_theme_supports( 'cvincludes-dropdowns', trailingslashit( CVINCLUDES_DROPDOWNS_DIR ) . 'dropdowns.php' );	
		
		require_if_theme_supports( 'cvincludes-portfolio', trailingslashit( CVINCLUDES_PORTFOLIO_DIR ) . 'portfolio.php' );	
		
		require_if_theme_supports( 'cvincludes-eztables', trailingslashit( CVINCLUDES_EZTABLES_DIR ) . 'eztables.php' );	
		
	}

}

?>